package com.bjpowernode.crm.workbench.service.impl;

import com.bjpowernode.crm.commons.utils.DateUtils;
import com.bjpowernode.crm.commons.utils.UUIDUtils;
import com.bjpowernode.crm.workbench.domain.Customer;
import com.bjpowernode.crm.workbench.mapper.CustomerMapper;
import com.bjpowernode.crm.workbench.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 郭俊才
 * 2021/8/30
 */
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public int saveSelective(Customer customer) {
        //设置主键
        customer.setId(UUIDUtils.getUUID());
        //设置创建时间
        customer.setCreateTime(DateUtils.formatDateTime(new Date()));
        return customerMapper.insertSelective(customer);
    }

    @Override
    public int removeByPrimaryKey(String id) {
        return customerMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int editByPrimaryKeySelective(Customer customer) {
        //设置修改时间
        customer.setEditTime(DateUtils.formatDateTime(new Date()));
        return customerMapper.updateByPrimaryKeySelective(customer);
    }

    @Override
    public Customer queryByPrimaryKey(String id) {
        return customerMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Customer> queryAllByCondition(Customer customer) {
        return customerMapper.selectAllByCondition(customer);
    }

    @Override
    public Customer queryByPrimaryKeyForDetails(String id) {
        return customerMapper.selectByPrimaryKeyForDetails(id);
    }

    @Override
    public List<Customer> queryCustomerByName(String customerName) {
        return customerMapper.selectCustomerByName(customerName);
    }
}
